package com.example.lib_base.state

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update

class RealContainer<STATE:UiState>(initState: STATE):MutableContainer<STATE> {

    private val _requestFlow= MutableStateFlow(RequestState(false,false,false,false,false))
    private val _uiFlow= MutableStateFlow(initState)

    override fun updateRequestState(action: RequestState.() -> RequestState) {
        _requestFlow.update { action(_requestFlow.value) }
    }

    override fun updateUiState(action: STATE.() -> STATE) {
        _uiFlow.update { action(_uiFlow.value) }
    }

    override val requestFlow: StateFlow<RequestState>
        get() = _requestFlow
    override val uiFlow: StateFlow<UiState>
        get() = _uiFlow
}